package com.yanqu.road.server.cmd.activity.ppl;

import com.yanqu.road.entity.activity.ppl.PplUserData;
import com.yanqu.road.server.pb.PplPb;
import com.yanqu.road.pb.activity.PplProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ppl.PplModule;
import com.yanqu.road.server.manger.activity.ppl.PplMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_PPL_USER_DATA, desc = "泡泡龙获取用户数据")
public class GetUserDataCmd extends AbstractCommand {

    private PplProto.PplUserDataMsg.Builder userDataMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!PplMgr.isActivityInShowTime()) {
            ret = GameErrorCode.E_ACTIVITY_PPL_NO_IN_SHOW_TIME;
        }
        PplModule pplModule = player.getModule(PplModule.class);

        PplUserData userData = pplModule.getUserData();
        userDataMsg = PplPb.parsePplUserDataMsg(userData);
    }

    @Override
    public void sendData(GamePlayer player) {
        PplProto.GetPplUserDataRespMsg.Builder builder = PplProto.GetPplUserDataRespMsg.newBuilder();
        builder.setRet(ret);
        if (ret == 0) {
            builder.setUserData(userDataMsg);
        }
        player.sendPacket(ClientProtocol.U_ACTIVITY_PPL_USER_DATA, builder);
    }
}
